package test.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import test.my_argumentResolver.AuthParamResolver;
import test.my_interceptor.WhitelistInterceptor;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @ project name : example
 * @ Author: XuLeHuang
 * @ Date: 2022/6/24 20:32
 * @ Description:
 */
@Configuration
public class MvcConfiguration implements WebMvcConfigurer {
    @Autowired
    private WhitelistInterceptor whitelistInterceptor;
    @Autowired
    private AuthParamResolver authParamResolver;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        /**
         * 注意：是/**，不是/*，否则不走拦截器
         */
        registry.addInterceptor(whitelistInterceptor).addPathPatterns("/**").order(1);
        // 这里可以配置拦截器启用的 path 的顺序，在有多个拦截器存在时，任一拦截器返回 false 都会使后续的请求方法不再执行
    }

    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
        argumentResolvers.add(authParamResolver);
    }
}
